package com.lianxi.handler;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.lianxi.utils.CommonResult;
import com.lianxi.utils.ResponseUtil;
import org.springframework.security.authentication.*;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class MyAuthenticationFailureHandler implements AuthenticationFailureHandler {


    @Override
    public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
        if (e instanceof DisabledException) {
            ResponseUtil.errorDataToJson(httpServletResponse,"账户已经被禁用！");
        } else {
            ResponseUtil.errorDataToJson(httpServletResponse,"账号或者密码错误！");

        }
    }
}
